<script>
    // 优化版本
    var fruits = ['香蕉', '苹果', '雪梨', '火龙果', '木瓜', '荔枝'];
    var str = '';
    for (var i = 0; i < fruits.length; i++) {
        var item = fruits[i];
        var color;

        switch (item) {
            case '香蕉':
                color = 'yellow';
                break;
            case '苹果':
                color = 'red';
                break;
            case '雪梨':
                color = 'blue';
                break;
            case '火龙果':
                color = 'pink';
                break;
            default:
                color = 'black';
        }
        str += `<li style="color:${color}">${item}</li>`;
    }
    document.write(str);
</script>